<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg10.php" ?>
<?php include_once "ewmysql10.php" ?>
<?php include_once "phpfn10.php" ?>
<?php include_once "creditosinfo.php" ?>
<?php include_once "usuariosinfo.php" ?>
<?php include_once "cuotascreditogridcls.php" ?>
<?php include_once "userfn10.php" ?>
<?php

//
// Page class
//

$creditos_edit = NULL; // Initialize page object first

class ccreditos_edit extends ccreditos {

	// Page ID
	var $PageID = 'edit';

	// Project ID
	var $ProjectID = "{320446D7-E035-4611-AE9B-94BD19ABA249}";

	// Table name
	var $TableName = 'creditos';

	// Page object name
	var $PageObjName = 'creditos_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		if ($this->UseTokenInUrl) $PageUrl .= "t=" . $this->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	function getWarningMessage() {
		return @$_SESSION[EW_SESSION_WARNING_MESSAGE];
	}

	function setWarningMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$hidden = FALSE;
		$html = "";

		// Message
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sMessage . "</div>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$sWarningMessage = $this->getWarningMessage();
		$this->Message_Showing($sWarningMessage, "warning");
		if ($sWarningMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sWarningMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sWarningMessage;
			$html .= "<div class=\"alert alert-warning ewWarning\">" . $sWarningMessage . "</div>";
			$_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sSuccessMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sSuccessMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sSuccessMessage . "</div>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sErrorMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sErrorMessage;
			$html .= "<div class=\"alert alert-error ewError\">" . $sErrorMessage . "</div>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo "<table class=\"ewStdTable\"><tr><td><div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div></td></tr></table>";
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p>" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Footer exists, display
			echo "<p>" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm;
		if ($this->UseTokenInUrl) {
			if ($objForm)
				return ($this->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($this->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function __construct() {
		global $conn, $Language;
		$GLOBALS["Page"] = &$this;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Parent constuctor
		parent::__construct();

		// Table object (creditos)
		if (!isset($GLOBALS["creditos"]) || get_class($GLOBALS["creditos"]) == "ccreditos") {
			$GLOBALS["creditos"] = &$this;
			$GLOBALS["Table"] = &$GLOBALS["creditos"];
		}

		// Table object (usuarios)
		if (!isset($GLOBALS['usuarios'])) $GLOBALS['usuarios'] = new cusuarios();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'creditos', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->ProjectID . $this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanEdit()) {
			$Security->SaveLastUrl();
			$this->setFailureMessage($Language->Phrase("NoPermission")); // Set no permission
			$this->Page_Terminate("creditoslist.php");
		}

		// Create form object
		$objForm = new cFormObj();
		$this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up current action
		$this->id->Visible = !$this->IsAdd() && !$this->IsCopy() && !$this->IsGridAdd();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter;
	var $DbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError;

		// Load key from QueryString
		if (@$_GET["id"] <> "") {
			$this->id->setQueryStringValue($_GET["id"]);
		}

		// Set up Breadcrumb
		$this->SetupBreadcrumb();

		// Process form if post back
		if (@$_POST["a_edit"] <> "") {
			$this->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values

			// Set up detail parameters
			$this->SetUpDetailParms();
		} else {
			$this->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($this->id->CurrentValue == "")
			$this->Page_Terminate("creditoslist.php"); // Invalid key, return to list

		// Validate form if post back
		if (@$_POST["a_edit"] <> "") {
			if (!$this->ValidateForm()) {
				$this->CurrentAction = ""; // Form error, reset action
				$this->setFailureMessage($gsFormError);
				$this->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		}
		switch ($this->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					if ($this->getFailureMessage() == "") $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("creditoslist.php"); // No matching record, return to list
				}

				// Set up detail parameters
				$this->SetUpDetailParms();
				break;
			Case "U": // Update
				$this->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
					if ($this->getCurrentDetailTable() <> "") // Master/detail edit
						$sReturnUrl = $this->GetDetailUrl();
					else
						$sReturnUrl = $this->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed

					// Set up detail parameters
					$this->SetUpDetailParms();
				}
		}

		// Render the record
		$this->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$this->ResetAttrs();
		$this->RenderRow();
	}

	// Set up starting record parameters
	function SetUpStartRec() {
		if ($this->DisplayRecs == 0)
			return;
		if ($this->IsPageRequest()) { // Validate request
			if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
				$this->StartRec = $_GET[EW_TABLE_START_REC];
				$this->setStartRecordNumber($this->StartRec);
			} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
				$PageNo = $_GET[EW_TABLE_PAGE_NO];
				if (is_numeric($PageNo)) {
					$this->StartRec = ($PageNo-1)*$this->DisplayRecs+1;
					if ($this->StartRec <= 0) {
						$this->StartRec = 1;
					} elseif ($this->StartRec >= intval(($this->TotalRecs-1)/$this->DisplayRecs)*$this->DisplayRecs+1) {
						$this->StartRec = intval(($this->TotalRecs-1)/$this->DisplayRecs)*$this->DisplayRecs+1;
					}
					$this->setStartRecordNumber($this->StartRec);
				}
			}
		}
		$this->StartRec = $this->getStartRecordNumber();

		// Check if correct start record counter
		if (!is_numeric($this->StartRec) || $this->StartRec == "") { // Avoid invalid start record counter
			$this->StartRec = 1; // Reset start record counter
			$this->setStartRecordNumber($this->StartRec);
		} elseif (intval($this->StartRec) > intval($this->TotalRecs)) { // Avoid starting record > total records
			$this->StartRec = intval(($this->TotalRecs-1)/$this->DisplayRecs)*$this->DisplayRecs+1; // Point to last page first record
			$this->setStartRecordNumber($this->StartRec);
		} elseif (($this->StartRec-1) % $this->DisplayRecs <> 0) {
			$this->StartRec = intval(($this->StartRec-1)/$this->DisplayRecs)*$this->DisplayRecs+1; // Point to page boundary
			$this->setStartRecordNumber($this->StartRec);
		}
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm;

		// Get upload data
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm;
		if (!$this->id->FldIsDetailKey)
			$this->id->setFormValue($objForm->GetValue("x_id"));
		if (!$this->fecha->FldIsDetailKey) {
			$this->fecha->setFormValue($objForm->GetValue("x_fecha"));
			$this->fecha->CurrentValue = ew_UnFormatDateTime($this->fecha->CurrentValue, 7);
		}
		if (!$this->usuario->FldIsDetailKey) {
			$this->usuario->setFormValue($objForm->GetValue("x_usuario"));
		}
		if (!$this->financiera->FldIsDetailKey) {
			$this->financiera->setFormValue($objForm->GetValue("x_financiera"));
		}
		if (!$this->tipoplan->FldIsDetailKey) {
			$this->tipoplan->setFormValue($objForm->GetValue("x_tipoplan"));
		}
		if (!$this->amortizacion->FldIsDetailKey) {
			$this->amortizacion->setFormValue($objForm->GetValue("x_amortizacion"));
		}
		if (!$this->cliente->FldIsDetailKey) {
			$this->cliente->setFormValue($objForm->GetValue("x_cliente"));
		}
		if (!$this->tipoCredito->FldIsDetailKey) {
			$this->tipoCredito->setFormValue($objForm->GetValue("x_tipoCredito"));
		}
		if (!$this->creditoAnterior->FldIsDetailKey) {
			$this->creditoAnterior->setFormValue($objForm->GetValue("x_creditoAnterior"));
		}
		if (!$this->estado->FldIsDetailKey) {
			$this->estado->setFormValue($objForm->GetValue("x_estado"));
		}
		if (!$this->autorizacion->FldIsDetailKey) {
			$this->autorizacion->setFormValue($objForm->GetValue("x_autorizacion"));
		}
		if (!$this->gracia->FldIsDetailKey) {
			$this->gracia->setFormValue($objForm->GetValue("x_gracia"));
		}
		if (!$this->tasa->FldIsDetailKey) {
			$this->tasa->setFormValue($objForm->GetValue("x_tasa"));
		}
		if (!$this->activo->FldIsDetailKey) {
			$this->activo->setFormValue($objForm->GetValue("x_activo"));
		}
		if (!$this->primerVencimiento->FldIsDetailKey) {
			$this->primerVencimiento->setFormValue($objForm->GetValue("x_primerVencimiento"));
			$this->primerVencimiento->CurrentValue = ew_UnFormatDateTime($this->primerVencimiento->CurrentValue, 7);
		}
		if (!$this->cuotas->FldIsDetailKey) {
			$this->cuotas->setFormValue($objForm->GetValue("x_cuotas"));
		}
		if (!$this->diaVto->FldIsDetailKey) {
			$this->diaVto->setFormValue($objForm->GetValue("x_diaVto"));
		}
		if (!$this->observacion->FldIsDetailKey) {
			$this->observacion->setFormValue($objForm->GetValue("x_observacion"));
		}
		if (!$this->monto->FldIsDetailKey) {
			$this->monto->setFormValue($objForm->GetValue("x_monto"));
		}
		if (!$this->sucursal->FldIsDetailKey) {
			$this->sucursal->setFormValue($objForm->GetValue("x_sucursal"));
		}
		if (!$this->nivelMorosidad->FldIsDetailKey) {
			$this->nivelMorosidad->setFormValue($objForm->GetValue("x_nivelMorosidad"));
		}
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm;
		$this->LoadRow();
		$this->id->CurrentValue = $this->id->FormValue;
		$this->fecha->CurrentValue = $this->fecha->FormValue;
		$this->fecha->CurrentValue = ew_UnFormatDateTime($this->fecha->CurrentValue, 7);
		$this->usuario->CurrentValue = $this->usuario->FormValue;
		$this->financiera->CurrentValue = $this->financiera->FormValue;
		$this->tipoplan->CurrentValue = $this->tipoplan->FormValue;
		$this->amortizacion->CurrentValue = $this->amortizacion->FormValue;
		$this->cliente->CurrentValue = $this->cliente->FormValue;
		$this->tipoCredito->CurrentValue = $this->tipoCredito->FormValue;
		$this->creditoAnterior->CurrentValue = $this->creditoAnterior->FormValue;
		$this->estado->CurrentValue = $this->estado->FormValue;
		$this->autorizacion->CurrentValue = $this->autorizacion->FormValue;
		$this->gracia->CurrentValue = $this->gracia->FormValue;
		$this->tasa->CurrentValue = $this->tasa->FormValue;
		$this->activo->CurrentValue = $this->activo->FormValue;
		$this->primerVencimiento->CurrentValue = $this->primerVencimiento->FormValue;
		$this->primerVencimiento->CurrentValue = ew_UnFormatDateTime($this->primerVencimiento->CurrentValue, 7);
		$this->cuotas->CurrentValue = $this->cuotas->FormValue;
		$this->diaVto->CurrentValue = $this->diaVto->FormValue;
		$this->observacion->CurrentValue = $this->observacion->FormValue;
		$this->monto->CurrentValue = $this->monto->FormValue;
		$this->sucursal->CurrentValue = $this->sucursal->FormValue;
		$this->nivelMorosidad->CurrentValue = $this->nivelMorosidad->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();

		// Call Row Selecting event
		$this->Row_Selecting($sFilter);

		// Load SQL based on filter
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row = &$rs->fields;
		$this->Row_Selected($row);
		$this->id->setDbValue($rs->fields('id'));
		$this->fecha->setDbValue($rs->fields('fecha'));
		$this->usuario->setDbValue($rs->fields('usuario'));
		$this->financiera->setDbValue($rs->fields('financiera'));
		$this->tipoplan->setDbValue($rs->fields('tipoplan'));
		$this->amortizacion->setDbValue($rs->fields('amortizacion'));
		$this->cliente->setDbValue($rs->fields('cliente'));
		$this->tipoCredito->setDbValue($rs->fields('tipoCredito'));
		$this->creditoAnterior->setDbValue($rs->fields('creditoAnterior'));
		$this->estado->setDbValue($rs->fields('estado'));
		$this->autorizacion->setDbValue($rs->fields('autorizacion'));
		$this->gracia->setDbValue($rs->fields('gracia'));
		$this->tasa->setDbValue($rs->fields('tasa'));
		$this->activo->setDbValue($rs->fields('activo'));
		$this->primerVencimiento->setDbValue($rs->fields('primerVencimiento'));
		$this->cuotas->setDbValue($rs->fields('cuotas'));
		$this->diaVto->setDbValue($rs->fields('diaVto'));
		$this->observacion->setDbValue($rs->fields('observacion'));
		$this->monto->setDbValue($rs->fields('monto'));
		$this->sucursal->setDbValue($rs->fields('sucursal'));
		$this->nivelMorosidad->setDbValue($rs->fields('nivelMorosidad'));
	}

	// Load DbValue from recordset
	function LoadDbValues(&$rs) {
		if (!$rs || !is_array($rs) && $rs->EOF) return;
		$row = is_array($rs) ? $rs : $rs->fields;
		$this->id->DbValue = $row['id'];
		$this->fecha->DbValue = $row['fecha'];
		$this->usuario->DbValue = $row['usuario'];
		$this->financiera->DbValue = $row['financiera'];
		$this->tipoplan->DbValue = $row['tipoplan'];
		$this->amortizacion->DbValue = $row['amortizacion'];
		$this->cliente->DbValue = $row['cliente'];
		$this->tipoCredito->DbValue = $row['tipoCredito'];
		$this->creditoAnterior->DbValue = $row['creditoAnterior'];
		$this->estado->DbValue = $row['estado'];
		$this->autorizacion->DbValue = $row['autorizacion'];
		$this->gracia->DbValue = $row['gracia'];
		$this->tasa->DbValue = $row['tasa'];
		$this->activo->DbValue = $row['activo'];
		$this->primerVencimiento->DbValue = $row['primerVencimiento'];
		$this->cuotas->DbValue = $row['cuotas'];
		$this->diaVto->DbValue = $row['diaVto'];
		$this->observacion->DbValue = $row['observacion'];
		$this->monto->DbValue = $row['monto'];
		$this->sucursal->DbValue = $row['sucursal'];
		$this->nivelMorosidad->DbValue = $row['nivelMorosidad'];
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language;
		global $gsLanguage;

		// Initialize URLs
		// Convert decimal values if posted back

		if ($this->tasa->FormValue == $this->tasa->CurrentValue && is_numeric(ew_StrToFloat($this->tasa->CurrentValue)))
			$this->tasa->CurrentValue = ew_StrToFloat($this->tasa->CurrentValue);

		// Convert decimal values if posted back
		if ($this->monto->FormValue == $this->monto->CurrentValue && is_numeric(ew_StrToFloat($this->monto->CurrentValue)))
			$this->monto->CurrentValue = ew_StrToFloat($this->monto->CurrentValue);

		// Call Row_Rendering event
		$this->Row_Rendering();

		// Common render codes for all row types
		// id
		// fecha
		// usuario
		// financiera
		// tipoplan
		// amortizacion
		// cliente
		// tipoCredito
		// creditoAnterior
		// estado
		// autorizacion
		// gracia
		// tasa
		// activo
		// primerVencimiento
		// cuotas
		// diaVto
		// observacion
		// monto
		// sucursal
		// nivelMorosidad

		if ($this->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$this->id->ViewValue = $this->id->CurrentValue;
			$this->id->ViewCustomAttributes = "";

			// fecha
			$this->fecha->ViewValue = $this->fecha->CurrentValue;
			$this->fecha->ViewValue = ew_FormatDateTime($this->fecha->ViewValue, 7);
			$this->fecha->ViewCustomAttributes = "";

			// usuario
			$this->usuario->ViewValue = $this->usuario->CurrentValue;
			$this->usuario->ViewCustomAttributes = "";

			// financiera
			if (strval($this->financiera->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->financiera->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `tipocreditos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->financiera, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->financiera->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->financiera->ViewValue = $this->financiera->CurrentValue;
				}
			} else {
				$this->financiera->ViewValue = NULL;
			}
			$this->financiera->ViewCustomAttributes = "";

			// tipoplan
			if (strval($this->tipoplan->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->tipoplan->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `planes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->tipoplan, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->tipoplan->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->tipoplan->ViewValue = $this->tipoplan->CurrentValue;
				}
			} else {
				$this->tipoplan->ViewValue = NULL;
			}
			$this->tipoplan->ViewCustomAttributes = "";

			// amortizacion
			$this->amortizacion->ViewValue = $this->amortizacion->CurrentValue;
			$this->amortizacion->ViewCustomAttributes = "";

			// cliente
			$this->cliente->ViewValue = $this->cliente->CurrentValue;
			if (strval($this->cliente->CurrentValue) <> "") {
				$sFilterWrk = "`Dni`" . ew_SearchString("=", $this->cliente->CurrentValue, EW_DATATYPE_STRING);
			$sSqlWrk = "SELECT `Dni`, `Apellido` AS `DispFld`, `Nombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `clientes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->cliente, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->cliente->ViewValue = $rswrk->fields('DispFld');
					$this->cliente->ViewValue .= ew_ValueSeparator(1,$this->cliente) . $rswrk->fields('Disp2Fld');
					$rswrk->Close();
				} else {
					$this->cliente->ViewValue = $this->cliente->CurrentValue;
				}
			} else {
				$this->cliente->ViewValue = NULL;
			}
			$this->cliente->ViewCustomAttributes = "";

			// tipoCredito
			if (strval($this->tipoCredito->CurrentValue) <> "") {
				switch ($this->tipoCredito->CurrentValue) {
					case $this->tipoCredito->FldTagValue(1):
						$this->tipoCredito->ViewValue = $this->tipoCredito->FldTagCaption(1) <> "" ? $this->tipoCredito->FldTagCaption(1) : $this->tipoCredito->CurrentValue;
						break;
					case $this->tipoCredito->FldTagValue(2):
						$this->tipoCredito->ViewValue = $this->tipoCredito->FldTagCaption(2) <> "" ? $this->tipoCredito->FldTagCaption(2) : $this->tipoCredito->CurrentValue;
						break;
					default:
						$this->tipoCredito->ViewValue = $this->tipoCredito->CurrentValue;
				}
			} else {
				$this->tipoCredito->ViewValue = NULL;
			}
			$this->tipoCredito->ViewCustomAttributes = "";

			// creditoAnterior
			$this->creditoAnterior->ViewValue = $this->creditoAnterior->CurrentValue;
			$this->creditoAnterior->ViewCustomAttributes = "";

			// estado
			if (strval($this->estado->CurrentValue) <> "") {
				switch ($this->estado->CurrentValue) {
					case $this->estado->FldTagValue(1):
						$this->estado->ViewValue = $this->estado->FldTagCaption(1) <> "" ? $this->estado->FldTagCaption(1) : $this->estado->CurrentValue;
						break;
					case $this->estado->FldTagValue(2):
						$this->estado->ViewValue = $this->estado->FldTagCaption(2) <> "" ? $this->estado->FldTagCaption(2) : $this->estado->CurrentValue;
						break;
					case $this->estado->FldTagValue(3):
						$this->estado->ViewValue = $this->estado->FldTagCaption(3) <> "" ? $this->estado->FldTagCaption(3) : $this->estado->CurrentValue;
						break;
					default:
						$this->estado->ViewValue = $this->estado->CurrentValue;
				}
			} else {
				$this->estado->ViewValue = NULL;
			}
			$this->estado->ViewCustomAttributes = "";

			// autorizacion
			$this->autorizacion->ViewValue = $this->autorizacion->CurrentValue;
			$this->autorizacion->ViewCustomAttributes = "";

			// gracia
			$this->gracia->ViewValue = $this->gracia->CurrentValue;
			$this->gracia->ViewCustomAttributes = "";

			// tasa
			$this->tasa->ViewValue = $this->tasa->CurrentValue;
			$this->tasa->ViewCustomAttributes = "";

			// activo
			$this->activo->ViewValue = $this->activo->CurrentValue;
			$this->activo->ViewCustomAttributes = "";

			// primerVencimiento
			$this->primerVencimiento->ViewValue = $this->primerVencimiento->CurrentValue;
			$this->primerVencimiento->ViewValue = ew_FormatDateTime($this->primerVencimiento->ViewValue, 7);
			$this->primerVencimiento->ViewCustomAttributes = "";

			// cuotas
			$this->cuotas->ViewValue = $this->cuotas->CurrentValue;
			$this->cuotas->ViewCustomAttributes = "";

			// diaVto
			$this->diaVto->ViewValue = $this->diaVto->CurrentValue;
			$this->diaVto->ViewCustomAttributes = "";

			// observacion
			$this->observacion->ViewValue = $this->observacion->CurrentValue;
			$this->observacion->ViewCustomAttributes = "";

			// monto
			$this->monto->ViewValue = $this->monto->CurrentValue;
			$this->monto->ViewCustomAttributes = "";

			// sucursal
			if (strval($this->sucursal->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->sucursal->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `sucursales`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->sucursal, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->sucursal->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->sucursal->ViewValue = $this->sucursal->CurrentValue;
				}
			} else {
				$this->sucursal->ViewValue = NULL;
			}
			$this->sucursal->ViewCustomAttributes = "";

			// nivelMorosidad
			$this->nivelMorosidad->ViewValue = $this->nivelMorosidad->CurrentValue;
			$this->nivelMorosidad->ViewCustomAttributes = "";

			// id
			$this->id->LinkCustomAttributes = "";
			$this->id->HrefValue = "";
			$this->id->TooltipValue = "";

			// fecha
			$this->fecha->LinkCustomAttributes = "";
			$this->fecha->HrefValue = "";
			$this->fecha->TooltipValue = "";

			// usuario
			$this->usuario->LinkCustomAttributes = "";
			$this->usuario->HrefValue = "";
			$this->usuario->TooltipValue = "";

			// financiera
			$this->financiera->LinkCustomAttributes = "";
			$this->financiera->HrefValue = "";
			$this->financiera->TooltipValue = "";

			// tipoplan
			$this->tipoplan->LinkCustomAttributes = "";
			$this->tipoplan->HrefValue = "";
			$this->tipoplan->TooltipValue = "";

			// amortizacion
			$this->amortizacion->LinkCustomAttributes = "";
			$this->amortizacion->HrefValue = "";
			$this->amortizacion->TooltipValue = "";

			// cliente
			$this->cliente->LinkCustomAttributes = "";
			$this->cliente->HrefValue = "";
			$this->cliente->TooltipValue = "";

			// tipoCredito
			$this->tipoCredito->LinkCustomAttributes = "";
			$this->tipoCredito->HrefValue = "";
			$this->tipoCredito->TooltipValue = "";

			// creditoAnterior
			$this->creditoAnterior->LinkCustomAttributes = "";
			$this->creditoAnterior->HrefValue = "";
			$this->creditoAnterior->TooltipValue = "";

			// estado
			$this->estado->LinkCustomAttributes = "";
			$this->estado->HrefValue = "";
			$this->estado->TooltipValue = "";

			// autorizacion
			$this->autorizacion->LinkCustomAttributes = "";
			$this->autorizacion->HrefValue = "";
			$this->autorizacion->TooltipValue = "";

			// gracia
			$this->gracia->LinkCustomAttributes = "";
			$this->gracia->HrefValue = "";
			$this->gracia->TooltipValue = "";

			// tasa
			$this->tasa->LinkCustomAttributes = "";
			$this->tasa->HrefValue = "";
			$this->tasa->TooltipValue = "";

			// activo
			$this->activo->LinkCustomAttributes = "";
			$this->activo->HrefValue = "";
			$this->activo->TooltipValue = "";

			// primerVencimiento
			$this->primerVencimiento->LinkCustomAttributes = "";
			$this->primerVencimiento->HrefValue = "";
			$this->primerVencimiento->TooltipValue = "";

			// cuotas
			$this->cuotas->LinkCustomAttributes = "";
			$this->cuotas->HrefValue = "";
			$this->cuotas->TooltipValue = "";

			// diaVto
			$this->diaVto->LinkCustomAttributes = "";
			$this->diaVto->HrefValue = "";
			$this->diaVto->TooltipValue = "";

			// observacion
			$this->observacion->LinkCustomAttributes = "";
			$this->observacion->HrefValue = "";
			$this->observacion->TooltipValue = "";

			// monto
			$this->monto->LinkCustomAttributes = "";
			$this->monto->HrefValue = "";
			$this->monto->TooltipValue = "";

			// sucursal
			$this->sucursal->LinkCustomAttributes = "";
			$this->sucursal->HrefValue = "";
			$this->sucursal->TooltipValue = "";

			// nivelMorosidad
			$this->nivelMorosidad->LinkCustomAttributes = "";
			$this->nivelMorosidad->HrefValue = "";
			$this->nivelMorosidad->TooltipValue = "";
		} elseif ($this->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// id
			$this->id->EditCustomAttributes = "";
			$this->id->EditValue = $this->id->CurrentValue;
			$this->id->ViewCustomAttributes = "";

			// fecha
			$this->fecha->EditCustomAttributes = "";
			$this->fecha->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->fecha->CurrentValue, 7));
			$this->fecha->PlaceHolder = ew_RemoveHtml($this->fecha->FldCaption());

			// usuario
			$this->usuario->EditCustomAttributes = "";
			$this->usuario->EditValue = ew_HtmlEncode($this->usuario->CurrentValue);
			$this->usuario->PlaceHolder = ew_RemoveHtml($this->usuario->FldCaption());

			// financiera
			$this->financiera->EditCustomAttributes = "";
			$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `tipocreditos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->financiera, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->financiera->EditValue = $arwrk;

			// tipoplan
			$this->tipoplan->EditCustomAttributes = "";
			$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, `financiera` AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `planes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->tipoplan, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->tipoplan->EditValue = $arwrk;

			// amortizacion
			$this->amortizacion->EditCustomAttributes = "";
			$this->amortizacion->EditValue = ew_HtmlEncode($this->amortizacion->CurrentValue);
			$this->amortizacion->PlaceHolder = ew_RemoveHtml($this->amortizacion->FldCaption());

			// cliente
			$this->cliente->EditCustomAttributes = "";
			$this->cliente->EditValue = ew_HtmlEncode($this->cliente->CurrentValue);
			if (strval($this->cliente->CurrentValue) <> "") {
				$sFilterWrk = "`Dni`" . ew_SearchString("=", $this->cliente->CurrentValue, EW_DATATYPE_STRING);
			$sSqlWrk = "SELECT `Dni`, `Apellido` AS `DispFld`, `Nombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `clientes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->cliente, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->cliente->EditValue = ew_HtmlEncode($rswrk->fields('DispFld'));
					$this->cliente->EditValue .= ew_ValueSeparator(1,$this->cliente) . ew_HtmlEncode($rswrk->fields('Disp2Fld'));
					$rswrk->Close();
				} else {
					$this->cliente->EditValue = ew_HtmlEncode($this->cliente->CurrentValue);
				}
			} else {
				$this->cliente->EditValue = NULL;
			}
			$this->cliente->PlaceHolder = ew_RemoveHtml($this->cliente->FldCaption());

			// tipoCredito
			$this->tipoCredito->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->tipoCredito->FldTagValue(1), $this->tipoCredito->FldTagCaption(1) <> "" ? $this->tipoCredito->FldTagCaption(1) : $this->tipoCredito->FldTagValue(1));
			$arwrk[] = array($this->tipoCredito->FldTagValue(2), $this->tipoCredito->FldTagCaption(2) <> "" ? $this->tipoCredito->FldTagCaption(2) : $this->tipoCredito->FldTagValue(2));
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$this->tipoCredito->EditValue = $arwrk;

			// creditoAnterior
			$this->creditoAnterior->EditCustomAttributes = "";
			$this->creditoAnterior->EditValue = ew_HtmlEncode($this->creditoAnterior->CurrentValue);
			$this->creditoAnterior->PlaceHolder = ew_RemoveHtml($this->creditoAnterior->FldCaption());

			// estado
			$this->estado->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->estado->FldTagValue(1), $this->estado->FldTagCaption(1) <> "" ? $this->estado->FldTagCaption(1) : $this->estado->FldTagValue(1));
			$arwrk[] = array($this->estado->FldTagValue(2), $this->estado->FldTagCaption(2) <> "" ? $this->estado->FldTagCaption(2) : $this->estado->FldTagValue(2));
			$arwrk[] = array($this->estado->FldTagValue(3), $this->estado->FldTagCaption(3) <> "" ? $this->estado->FldTagCaption(3) : $this->estado->FldTagValue(3));
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$this->estado->EditValue = $arwrk;

			// autorizacion
			$this->autorizacion->EditCustomAttributes = "";
			$this->autorizacion->EditValue = ew_HtmlEncode($this->autorizacion->CurrentValue);
			$this->autorizacion->PlaceHolder = ew_RemoveHtml($this->autorizacion->FldCaption());

			// gracia
			$this->gracia->EditCustomAttributes = "";
			$this->gracia->EditValue = ew_HtmlEncode($this->gracia->CurrentValue);
			$this->gracia->PlaceHolder = ew_RemoveHtml($this->gracia->FldCaption());

			// tasa
			$this->tasa->EditCustomAttributes = "";
			$this->tasa->EditValue = ew_HtmlEncode($this->tasa->CurrentValue);
			$this->tasa->PlaceHolder = ew_RemoveHtml($this->tasa->FldCaption());
			if (strval($this->tasa->EditValue) <> "" && is_numeric($this->tasa->EditValue)) $this->tasa->EditValue = ew_FormatNumber($this->tasa->EditValue, -2, -1, -2, 0);

			// activo
			$this->activo->EditCustomAttributes = "";
			$this->activo->EditValue = ew_HtmlEncode($this->activo->CurrentValue);
			$this->activo->PlaceHolder = ew_RemoveHtml($this->activo->FldCaption());

			// primerVencimiento
			$this->primerVencimiento->EditCustomAttributes = "";
			$this->primerVencimiento->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->primerVencimiento->CurrentValue, 7));
			$this->primerVencimiento->PlaceHolder = ew_RemoveHtml($this->primerVencimiento->FldCaption());

			// cuotas
			$this->cuotas->EditCustomAttributes = "";
			$this->cuotas->EditValue = ew_HtmlEncode($this->cuotas->CurrentValue);
			$this->cuotas->PlaceHolder = ew_RemoveHtml($this->cuotas->FldCaption());

			// diaVto
			$this->diaVto->EditCustomAttributes = "";
			$this->diaVto->EditValue = ew_HtmlEncode($this->diaVto->CurrentValue);
			$this->diaVto->PlaceHolder = ew_RemoveHtml($this->diaVto->FldCaption());

			// observacion
			$this->observacion->EditCustomAttributes = "";
			$this->observacion->EditValue = $this->observacion->CurrentValue;
			$this->observacion->PlaceHolder = ew_RemoveHtml($this->observacion->FldCaption());

			// monto
			$this->monto->EditCustomAttributes = "";
			$this->monto->EditValue = ew_HtmlEncode($this->monto->CurrentValue);
			$this->monto->PlaceHolder = ew_RemoveHtml($this->monto->FldCaption());
			if (strval($this->monto->EditValue) <> "" && is_numeric($this->monto->EditValue)) $this->monto->EditValue = ew_FormatNumber($this->monto->EditValue, -2, -1, -2, 0);

			// sucursal
			$this->sucursal->EditCustomAttributes = "";
			if (trim(strval($this->sucursal->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->sucursal->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `sucursales`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->sucursal, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->sucursal->EditValue = $arwrk;

			// nivelMorosidad
			$this->nivelMorosidad->EditCustomAttributes = "";
			$this->nivelMorosidad->EditValue = ew_HtmlEncode($this->nivelMorosidad->CurrentValue);
			$this->nivelMorosidad->PlaceHolder = ew_RemoveHtml($this->nivelMorosidad->FldCaption());

			// Edit refer script
			// id

			$this->id->HrefValue = "";

			// fecha
			$this->fecha->HrefValue = "";

			// usuario
			$this->usuario->HrefValue = "";

			// financiera
			$this->financiera->HrefValue = "";

			// tipoplan
			$this->tipoplan->HrefValue = "";

			// amortizacion
			$this->amortizacion->HrefValue = "";

			// cliente
			$this->cliente->HrefValue = "";

			// tipoCredito
			$this->tipoCredito->HrefValue = "";

			// creditoAnterior
			$this->creditoAnterior->HrefValue = "";

			// estado
			$this->estado->HrefValue = "";

			// autorizacion
			$this->autorizacion->HrefValue = "";

			// gracia
			$this->gracia->HrefValue = "";

			// tasa
			$this->tasa->HrefValue = "";

			// activo
			$this->activo->HrefValue = "";

			// primerVencimiento
			$this->primerVencimiento->HrefValue = "";

			// cuotas
			$this->cuotas->HrefValue = "";

			// diaVto
			$this->diaVto->HrefValue = "";

			// observacion
			$this->observacion->HrefValue = "";

			// monto
			$this->monto->HrefValue = "";

			// sucursal
			$this->sucursal->HrefValue = "";

			// nivelMorosidad
			$this->nivelMorosidad->HrefValue = "";
		}
		if ($this->RowType == EW_ROWTYPE_ADD ||
			$this->RowType == EW_ROWTYPE_EDIT ||
			$this->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$this->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($this->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$this->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!ew_CheckEuroDate($this->fecha->FormValue)) {
			ew_AddMessage($gsFormError, $this->fecha->FldErrMsg());
		}
		if (!ew_CheckInteger($this->usuario->FormValue)) {
			ew_AddMessage($gsFormError, $this->usuario->FldErrMsg());
		}
		if (!ew_CheckInteger($this->amortizacion->FormValue)) {
			ew_AddMessage($gsFormError, $this->amortizacion->FldErrMsg());
		}
		if (!ew_CheckInteger($this->cliente->FormValue)) {
			ew_AddMessage($gsFormError, $this->cliente->FldErrMsg());
		}
		if (!ew_CheckInteger($this->creditoAnterior->FormValue)) {
			ew_AddMessage($gsFormError, $this->creditoAnterior->FldErrMsg());
		}
		if (!ew_CheckInteger($this->gracia->FormValue)) {
			ew_AddMessage($gsFormError, $this->gracia->FldErrMsg());
		}
		if (!ew_CheckNumber($this->tasa->FormValue)) {
			ew_AddMessage($gsFormError, $this->tasa->FldErrMsg());
		}
		if (!ew_CheckInteger($this->activo->FormValue)) {
			ew_AddMessage($gsFormError, $this->activo->FldErrMsg());
		}
		if (!ew_CheckEuroDate($this->primerVencimiento->FormValue)) {
			ew_AddMessage($gsFormError, $this->primerVencimiento->FldErrMsg());
		}
		if (!ew_CheckInteger($this->cuotas->FormValue)) {
			ew_AddMessage($gsFormError, $this->cuotas->FldErrMsg());
		}
		if (!ew_CheckInteger($this->diaVto->FormValue)) {
			ew_AddMessage($gsFormError, $this->diaVto->FldErrMsg());
		}
		if (!ew_CheckNumber($this->monto->FormValue)) {
			ew_AddMessage($gsFormError, $this->monto->FldErrMsg());
		}
		if (!ew_CheckInteger($this->nivelMorosidad->FormValue)) {
			ew_AddMessage($gsFormError, $this->nivelMorosidad->FldErrMsg());
		}

		// Validate detail grid
		$DetailTblVar = explode(",", $this->getCurrentDetailTable());
		if (in_array("cuotascredito", $DetailTblVar) && $GLOBALS["cuotascredito"]->DetailEdit) {
			if (!isset($GLOBALS["cuotascredito_grid"])) $GLOBALS["cuotascredito_grid"] = new ccuotascredito_grid(); // get detail page object
			$GLOBALS["cuotascredito_grid"]->ValidateGridForm();
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Begin transaction
			if ($this->getCurrentDetailTable() <> "")
				$conn->BeginTrans();

			// Save old values
			$rsold = &$rs->fields;
			$this->LoadDbValues($rsold);
			$rsnew = array();

			// fecha
			$this->fecha->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->fecha->CurrentValue, 7), NULL, $this->fecha->ReadOnly);

			// usuario
			$this->usuario->SetDbValueDef($rsnew, $this->usuario->CurrentValue, NULL, $this->usuario->ReadOnly);

			// financiera
			$this->financiera->SetDbValueDef($rsnew, $this->financiera->CurrentValue, NULL, $this->financiera->ReadOnly);

			// tipoplan
			$this->tipoplan->SetDbValueDef($rsnew, $this->tipoplan->CurrentValue, NULL, $this->tipoplan->ReadOnly);

			// amortizacion
			$this->amortizacion->SetDbValueDef($rsnew, $this->amortizacion->CurrentValue, NULL, $this->amortizacion->ReadOnly);

			// cliente
			$this->cliente->SetDbValueDef($rsnew, $this->cliente->CurrentValue, NULL, $this->cliente->ReadOnly);

			// tipoCredito
			$this->tipoCredito->SetDbValueDef($rsnew, $this->tipoCredito->CurrentValue, NULL, $this->tipoCredito->ReadOnly);

			// creditoAnterior
			$this->creditoAnterior->SetDbValueDef($rsnew, $this->creditoAnterior->CurrentValue, NULL, $this->creditoAnterior->ReadOnly);

			// estado
			$this->estado->SetDbValueDef($rsnew, $this->estado->CurrentValue, NULL, $this->estado->ReadOnly);

			// autorizacion
			$this->autorizacion->SetDbValueDef($rsnew, $this->autorizacion->CurrentValue, NULL, $this->autorizacion->ReadOnly);

			// gracia
			$this->gracia->SetDbValueDef($rsnew, $this->gracia->CurrentValue, NULL, $this->gracia->ReadOnly);

			// tasa
			$this->tasa->SetDbValueDef($rsnew, $this->tasa->CurrentValue, NULL, $this->tasa->ReadOnly);

			// activo
			$this->activo->SetDbValueDef($rsnew, $this->activo->CurrentValue, NULL, $this->activo->ReadOnly);

			// primerVencimiento
			$this->primerVencimiento->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->primerVencimiento->CurrentValue, 7), NULL, $this->primerVencimiento->ReadOnly);

			// cuotas
			$this->cuotas->SetDbValueDef($rsnew, $this->cuotas->CurrentValue, NULL, $this->cuotas->ReadOnly);

			// diaVto
			$this->diaVto->SetDbValueDef($rsnew, $this->diaVto->CurrentValue, NULL, $this->diaVto->ReadOnly);

			// observacion
			$this->observacion->SetDbValueDef($rsnew, $this->observacion->CurrentValue, NULL, $this->observacion->ReadOnly);

			// monto
			$this->monto->SetDbValueDef($rsnew, $this->monto->CurrentValue, NULL, $this->monto->ReadOnly);

			// sucursal
			$this->sucursal->SetDbValueDef($rsnew, $this->sucursal->CurrentValue, NULL, $this->sucursal->ReadOnly);

			// nivelMorosidad
			$this->nivelMorosidad->SetDbValueDef($rsnew, $this->nivelMorosidad->CurrentValue, NULL, $this->nivelMorosidad->ReadOnly);

			// Call Row Updating event
			$bUpdateRow = $this->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
				$conn->raiseErrorFn = 'ew_ErrorFn';
				if (count($rsnew) > 0)
					$EditRow = $this->Update($rsnew, "", $rsold);
				else
					$EditRow = TRUE; // No field to update
				$conn->raiseErrorFn = '';
				if ($EditRow) {
				}

				// Update detail records
				if ($EditRow) {
					$DetailTblVar = explode(",", $this->getCurrentDetailTable());
					if (in_array("cuotascredito", $DetailTblVar) && $GLOBALS["cuotascredito"]->DetailEdit) {
						if (!isset($GLOBALS["cuotascredito_grid"])) $GLOBALS["cuotascredito_grid"] = new ccuotascredito_grid(); // Get detail page object
						$EditRow = $GLOBALS["cuotascredito_grid"]->GridUpdate();
					}
				}

				// Commit/Rollback transaction
				if ($this->getCurrentDetailTable() <> "") {
					if ($EditRow) {
						$conn->CommitTrans(); // Commit transaction
					} else {
						$conn->RollbackTrans(); // Rollback transaction
					}
				}
			} else {
				if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

					// Use the message, do nothing
				} elseif ($this->CancelMessage <> "") {
					$this->setFailureMessage($this->CancelMessage);
					$this->CancelMessage = "";
				} else {
					$this->setFailureMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$this->Row_Updated($rsold, $rsnew);
		$rs->Close();
		return $EditRow;
	}

	// Set up detail parms based on QueryString
	function SetUpDetailParms() {

		// Get the keys for master table
		if (isset($_GET[EW_TABLE_SHOW_DETAIL])) {
			$sDetailTblVar = $_GET[EW_TABLE_SHOW_DETAIL];
			$this->setCurrentDetailTable($sDetailTblVar);
		} else {
			$sDetailTblVar = $this->getCurrentDetailTable();
		}
		if ($sDetailTblVar <> "") {
			$DetailTblVar = explode(",", $sDetailTblVar);
			if (in_array("cuotascredito", $DetailTblVar)) {
				if (!isset($GLOBALS["cuotascredito_grid"]))
					$GLOBALS["cuotascredito_grid"] = new ccuotascredito_grid;
				if ($GLOBALS["cuotascredito_grid"]->DetailEdit) {
					$GLOBALS["cuotascredito_grid"]->CurrentMode = "edit";
					$GLOBALS["cuotascredito_grid"]->CurrentAction = "gridedit";

					// Save current master table to detail table
					$GLOBALS["cuotascredito_grid"]->setCurrentMasterTable($this->TableVar);
					$GLOBALS["cuotascredito_grid"]->setStartRecordNumber(1);
					$GLOBALS["cuotascredito_grid"]->creditoId->FldIsDetailKey = TRUE;
					$GLOBALS["cuotascredito_grid"]->creditoId->CurrentValue = $this->id->CurrentValue;
					$GLOBALS["cuotascredito_grid"]->creditoId->setSessionValue($GLOBALS["cuotascredito_grid"]->creditoId->CurrentValue);
				}
			}
		}
	}

	// Set up Breadcrumb
	function SetupBreadcrumb() {
		global $Breadcrumb, $Language;
		$Breadcrumb = new cBreadcrumb();
		$Breadcrumb->Add("list", $this->TableVar, "creditoslist.php", $this->TableVar, TRUE);
		$PageId = "edit";
		$Breadcrumb->Add("edit", $PageId, ew_CurrentUrl());
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'|'warning'
	function Message_Showing(&$msg, $type) {
		if ($type == 'success') {

			//$msg = "your success message";
		} elseif ($type == 'failure') {

			//$msg = "your failure message";
		} elseif ($type == 'warning') {

			//$msg = "your warning message";
		} else {

			//$msg = "your message";
		}
	}

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
<?php ew_Header(FALSE) ?>
<?php

// Create page object
if (!isset($creditos_edit)) $creditos_edit = new ccreditos_edit();

// Page init
$creditos_edit->Page_Init();

// Page main
$creditos_edit->Page_Main();

// Global Page Rendering event (in userfn*.php)
Page_Rendering();

// Page Rendering event
$creditos_edit->Page_Render();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">

// Page object
var creditos_edit = new ew_Page("creditos_edit");
creditos_edit.PageID = "edit"; // Page ID
var EW_PAGE_ID = creditos_edit.PageID; // For backward compatibility

// Form object
var fcreditosedit = new ew_Form("fcreditosedit");

// Validate form
fcreditosedit.Validate = function() {
	if (!this.ValidateRequired)
		return true; // Ignore validation
	var $ = jQuery, fobj = this.GetForm(), $fobj = $(fobj);
	this.PostAutoSuggest();
	if ($fobj.find("#a_confirm").val() == "F")
		return true;
	var elm, felm, uelm, addcnt = 0;
	var $k = $fobj.find("#" + this.FormKeyCountName); // Get key_count
	var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
	var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
	var gridinsert = $fobj.find("#a_list").val() == "gridinsert";
	for (var i = startcnt; i <= rowcnt; i++) {
		var infix = ($k[0]) ? String(i) : "";
		$fobj.data("rowindex", infix);
			elm = this.GetElements("x" + infix + "_fecha");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->fecha->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_usuario");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->usuario->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_amortizacion");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->amortizacion->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_cliente");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->cliente->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_creditoAnterior");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->creditoAnterior->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_gracia");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->gracia->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_tasa");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->tasa->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_activo");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->activo->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_primerVencimiento");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->primerVencimiento->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_cuotas");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->cuotas->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_diaVto");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->diaVto->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_monto");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->monto->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_nivelMorosidad");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($creditos->nivelMorosidad->FldErrMsg()) ?>");

			// Set up row object
			ew_ElementsToRow(fobj);

			// Fire Form_CustomValidate event
			if (!this.Form_CustomValidate(fobj))
				return false;
	}

	// Process detail forms
	var dfs = $fobj.find("input[name='detailpage']").get();
	for (var i = 0; i < dfs.length; i++) {
		var df = dfs[i], val = df.value;
		if (val && ewForms[val])
			if (!ewForms[val].Validate())
				return false;
	}
	return true;
}

// Form_CustomValidate event
fcreditosedit.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }

// Use JavaScript validation or not
<?php if (EW_CLIENT_VALIDATE) { ?>
fcreditosedit.ValidateRequired = true;
<?php } else { ?>
fcreditosedit.ValidateRequired = false; 
<?php } ?>

// Dynamic selection lists
fcreditosedit.Lists["x_financiera"] = {"LinkField":"x_id","Ajax":null,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fcreditosedit.Lists["x_tipoplan"] = {"LinkField":"x_id","Ajax":null,"AutoFill":false,"DisplayFields":["x_nombre","","",""],"ParentFields":["x_financiera"],"FilterFields":["x_financiera"],"Options":[]};
fcreditosedit.Lists["x_cliente"] = {"LinkField":"x_Dni","Ajax":true,"AutoFill":false,"DisplayFields":["x_Apellido","x_Nombre","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fcreditosedit.Lists["x_sucursal"] = {"LinkField":"x_id","Ajax":true,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};

// Form object for search
</script>
<script type="text/javascript">

// Write your client script here, no need to add script tags.
</script>
<?php $Breadcrumb->Render(); ?>
<?php $creditos_edit->ShowPageHeader(); ?>
<?php
$creditos_edit->ShowMessage();
?>
<form name="fcreditosedit" id="fcreditosedit" class="ewForm form-inline" action="<?php echo ew_CurrentPage() ?>" method="post">
<input type="hidden" name="t" value="creditos">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table class="ewGrid"><tr><td>
<table id="tbl_creditosedit" class="table table-bordered table-striped">
<?php if ($creditos->id->Visible) { // id ?>
	<tr id="r_id">
		<td><span id="elh_creditos_id"><?php echo $creditos->id->FldCaption() ?></span></td>
		<td<?php echo $creditos->id->CellAttributes() ?>>
<span id="el_creditos_id" class="control-group">
<span<?php echo $creditos->id->ViewAttributes() ?>>
<?php echo $creditos->id->EditValue ?></span>
</span>
<input type="hidden" data-field="x_id" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($creditos->id->CurrentValue) ?>">
<?php echo $creditos->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->fecha->Visible) { // fecha ?>
	<tr id="r_fecha">
		<td><span id="elh_creditos_fecha"><?php echo $creditos->fecha->FldCaption() ?></span></td>
		<td<?php echo $creditos->fecha->CellAttributes() ?>>
<span id="el_creditos_fecha" class="control-group">
<input type="text" data-field="x_fecha" name="x_fecha" id="x_fecha" placeholder="<?php echo ew_HtmlEncode($creditos->fecha->PlaceHolder) ?>" value="<?php echo $creditos->fecha->EditValue ?>"<?php echo $creditos->fecha->EditAttributes() ?>>
<?php if (!$creditos->fecha->ReadOnly && !$creditos->fecha->Disabled && @$creditos->fecha->EditAttrs["readonly"] == "" && @$creditos->fecha->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_fecha" name="cal_x_fecha" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fcreditosedit", "x_fecha", "%d/%m/%Y");
</script>
<?php } ?>
</span>
<?php echo $creditos->fecha->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->usuario->Visible) { // usuario ?>
	<tr id="r_usuario">
		<td><span id="elh_creditos_usuario"><?php echo $creditos->usuario->FldCaption() ?></span></td>
		<td<?php echo $creditos->usuario->CellAttributes() ?>>
<span id="el_creditos_usuario" class="control-group">
<input type="text" data-field="x_usuario" name="x_usuario" id="x_usuario" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->usuario->PlaceHolder) ?>" value="<?php echo $creditos->usuario->EditValue ?>"<?php echo $creditos->usuario->EditAttributes() ?>>
</span>
<?php echo $creditos->usuario->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->financiera->Visible) { // financiera ?>
	<tr id="r_financiera">
		<td><span id="elh_creditos_financiera"><?php echo $creditos->financiera->FldCaption() ?></span></td>
		<td<?php echo $creditos->financiera->CellAttributes() ?>>
<span id="el_creditos_financiera" class="control-group">
<?php $creditos->financiera->EditAttrs["onchange"] = "ew_UpdateOpt.call(this, ['x_tipoplan']); " . @$creditos->financiera->EditAttrs["onchange"]; ?>
<select data-field="x_financiera" id="x_financiera" name="x_financiera"<?php echo $creditos->financiera->EditAttributes() ?>>
<?php
if (is_array($creditos->financiera->EditValue)) {
	$arwrk = $creditos->financiera->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($creditos->financiera->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<script type="text/javascript">
fcreditosedit.Lists["x_financiera"].Options = <?php echo (is_array($creditos->financiera->EditValue)) ? ew_ArrayToJson($creditos->financiera->EditValue, 1) : "[]" ?>;
</script>
</span>
<?php echo $creditos->financiera->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->tipoplan->Visible) { // tipoplan ?>
	<tr id="r_tipoplan">
		<td><span id="elh_creditos_tipoplan"><?php echo $creditos->tipoplan->FldCaption() ?></span></td>
		<td<?php echo $creditos->tipoplan->CellAttributes() ?>>
<span id="el_creditos_tipoplan" class="control-group">
<select data-field="x_tipoplan" id="x_tipoplan" name="x_tipoplan"<?php echo $creditos->tipoplan->EditAttributes() ?>>
<?php
if (is_array($creditos->tipoplan->EditValue)) {
	$arwrk = $creditos->tipoplan->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($creditos->tipoplan->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<script type="text/javascript">
fcreditosedit.Lists["x_tipoplan"].Options = <?php echo (is_array($creditos->tipoplan->EditValue)) ? ew_ArrayToJson($creditos->tipoplan->EditValue, 1) : "[]" ?>;
</script>
</span>
<?php echo $creditos->tipoplan->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->amortizacion->Visible) { // amortizacion ?>
	<tr id="r_amortizacion">
		<td><span id="elh_creditos_amortizacion"><?php echo $creditos->amortizacion->FldCaption() ?></span></td>
		<td<?php echo $creditos->amortizacion->CellAttributes() ?>>
<span id="el_creditos_amortizacion" class="control-group">
<input type="text" data-field="x_amortizacion" name="x_amortizacion" id="x_amortizacion" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->amortizacion->PlaceHolder) ?>" value="<?php echo $creditos->amortizacion->EditValue ?>"<?php echo $creditos->amortizacion->EditAttributes() ?>>
</span>
<?php echo $creditos->amortizacion->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->cliente->Visible) { // cliente ?>
	<tr id="r_cliente">
		<td><span id="elh_creditos_cliente"><?php echo $creditos->cliente->FldCaption() ?></span></td>
		<td<?php echo $creditos->cliente->CellAttributes() ?>>
<span id="el_creditos_cliente" class="control-group">
<?php
	$wrkonchange = trim(" " . @$creditos->cliente->EditAttrs["onchange"]);
	if ($wrkonchange <> "") $wrkonchange = " onchange=\"" . ew_JsEncode2($wrkonchange) . "\"";
	$creditos->cliente->EditAttrs["onchange"] = "";
?>
<span id="as_x_cliente" style="white-space: nowrap; z-index: 8930">
	<input type="text" name="sv_x_cliente" id="sv_x_cliente" value="<?php echo $creditos->cliente->EditValue ?>" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->cliente->PlaceHolder) ?>"<?php echo $creditos->cliente->EditAttributes() ?>>&nbsp;<span id="em_x_cliente" class="ewMessage" style="display: none"><?php echo str_replace("%f", "phpimages/", $Language->Phrase("UnmatchedValue")) ?></span>
	<div id="sc_x_cliente" style="display: inline; z-index: 8930"></div>
</span>
<input type="hidden" data-field="x_cliente" name="x_cliente" id="x_cliente" value="<?php echo ew_HtmlEncode($creditos->cliente->CurrentValue) ?>"<?php echo $wrkonchange ?>>
<?php
$sSqlWrk = "SELECT `Dni`, `Apellido` AS `DispFld`, `Nombre` AS `Disp2Fld` FROM `clientes`";
$sWhereWrk = "`Apellido` LIKE '{query_value}%' OR CONCAT(`Apellido`,'" . ew_ValueSeparator(1, $Page->cliente) . "',`Nombre`) LIKE '{query_value}%'";

// Call Lookup selecting
$creditos->Lookup_Selecting($creditos->cliente, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
$sSqlWrk .= " LIMIT " . EW_AUTO_SUGGEST_MAX_ENTRIES;
?>
<input type="hidden" name="q_x_cliente" id="q_x_cliente" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>">
<script type="text/javascript">
var oas = new ew_AutoSuggest("x_cliente", fcreditosedit, false, EW_AUTO_SUGGEST_MAX_ENTRIES);
oas.formatResult = function(ar) {
	var dv = ar[1];
	for (var i = 2; i <= 4; i++)
		dv += (ar[i]) ? ew_ValueSeparator(i - 1, "x_cliente") + ar[i] : "";
	return dv;
}
fcreditosedit.AutoSuggests["x_cliente"] = oas;
</script>
</span>
<?php echo $creditos->cliente->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->tipoCredito->Visible) { // tipoCredito ?>
	<tr id="r_tipoCredito">
		<td><span id="elh_creditos_tipoCredito"><?php echo $creditos->tipoCredito->FldCaption() ?></span></td>
		<td<?php echo $creditos->tipoCredito->CellAttributes() ?>>
<span id="el_creditos_tipoCredito" class="control-group">
<select data-field="x_tipoCredito" id="x_tipoCredito" name="x_tipoCredito"<?php echo $creditos->tipoCredito->EditAttributes() ?>>
<?php
if (is_array($creditos->tipoCredito->EditValue)) {
	$arwrk = $creditos->tipoCredito->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($creditos->tipoCredito->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span>
<?php echo $creditos->tipoCredito->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->creditoAnterior->Visible) { // creditoAnterior ?>
	<tr id="r_creditoAnterior">
		<td><span id="elh_creditos_creditoAnterior"><?php echo $creditos->creditoAnterior->FldCaption() ?></span></td>
		<td<?php echo $creditos->creditoAnterior->CellAttributes() ?>>
<span id="el_creditos_creditoAnterior" class="control-group">
<input type="text" data-field="x_creditoAnterior" name="x_creditoAnterior" id="x_creditoAnterior" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->creditoAnterior->PlaceHolder) ?>" value="<?php echo $creditos->creditoAnterior->EditValue ?>"<?php echo $creditos->creditoAnterior->EditAttributes() ?>>
</span>
<?php echo $creditos->creditoAnterior->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->estado->Visible) { // estado ?>
	<tr id="r_estado">
		<td><span id="elh_creditos_estado"><?php echo $creditos->estado->FldCaption() ?></span></td>
		<td<?php echo $creditos->estado->CellAttributes() ?>>
<span id="el_creditos_estado" class="control-group">
<select data-field="x_estado" id="x_estado" name="x_estado"<?php echo $creditos->estado->EditAttributes() ?>>
<?php
if (is_array($creditos->estado->EditValue)) {
	$arwrk = $creditos->estado->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($creditos->estado->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span>
<?php echo $creditos->estado->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->autorizacion->Visible) { // autorizacion ?>
	<tr id="r_autorizacion">
		<td><span id="elh_creditos_autorizacion"><?php echo $creditos->autorizacion->FldCaption() ?></span></td>
		<td<?php echo $creditos->autorizacion->CellAttributes() ?>>
<span id="el_creditos_autorizacion" class="control-group">
<input type="text" data-field="x_autorizacion" name="x_autorizacion" id="x_autorizacion" size="30" maxlength="100" placeholder="<?php echo ew_HtmlEncode($creditos->autorizacion->PlaceHolder) ?>" value="<?php echo $creditos->autorizacion->EditValue ?>"<?php echo $creditos->autorizacion->EditAttributes() ?>>
</span>
<?php echo $creditos->autorizacion->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->gracia->Visible) { // gracia ?>
	<tr id="r_gracia">
		<td><span id="elh_creditos_gracia"><?php echo $creditos->gracia->FldCaption() ?></span></td>
		<td<?php echo $creditos->gracia->CellAttributes() ?>>
<span id="el_creditos_gracia" class="control-group">
<input type="text" data-field="x_gracia" name="x_gracia" id="x_gracia" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->gracia->PlaceHolder) ?>" value="<?php echo $creditos->gracia->EditValue ?>"<?php echo $creditos->gracia->EditAttributes() ?>>
</span>
<?php echo $creditos->gracia->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->tasa->Visible) { // tasa ?>
	<tr id="r_tasa">
		<td><span id="elh_creditos_tasa"><?php echo $creditos->tasa->FldCaption() ?></span></td>
		<td<?php echo $creditos->tasa->CellAttributes() ?>>
<span id="el_creditos_tasa" class="control-group">
<input type="text" data-field="x_tasa" name="x_tasa" id="x_tasa" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->tasa->PlaceHolder) ?>" value="<?php echo $creditos->tasa->EditValue ?>"<?php echo $creditos->tasa->EditAttributes() ?>>
</span>
<?php echo $creditos->tasa->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->activo->Visible) { // activo ?>
	<tr id="r_activo">
		<td><span id="elh_creditos_activo"><?php echo $creditos->activo->FldCaption() ?></span></td>
		<td<?php echo $creditos->activo->CellAttributes() ?>>
<span id="el_creditos_activo" class="control-group">
<input type="text" data-field="x_activo" name="x_activo" id="x_activo" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->activo->PlaceHolder) ?>" value="<?php echo $creditos->activo->EditValue ?>"<?php echo $creditos->activo->EditAttributes() ?>>
</span>
<?php echo $creditos->activo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->primerVencimiento->Visible) { // primerVencimiento ?>
	<tr id="r_primerVencimiento">
		<td><span id="elh_creditos_primerVencimiento"><?php echo $creditos->primerVencimiento->FldCaption() ?></span></td>
		<td<?php echo $creditos->primerVencimiento->CellAttributes() ?>>
<span id="el_creditos_primerVencimiento" class="control-group">
<input type="text" data-field="x_primerVencimiento" name="x_primerVencimiento" id="x_primerVencimiento" placeholder="<?php echo ew_HtmlEncode($creditos->primerVencimiento->PlaceHolder) ?>" value="<?php echo $creditos->primerVencimiento->EditValue ?>"<?php echo $creditos->primerVencimiento->EditAttributes() ?>>
</span>
<?php echo $creditos->primerVencimiento->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->cuotas->Visible) { // cuotas ?>
	<tr id="r_cuotas">
		<td><span id="elh_creditos_cuotas"><?php echo $creditos->cuotas->FldCaption() ?></span></td>
		<td<?php echo $creditos->cuotas->CellAttributes() ?>>
<span id="el_creditos_cuotas" class="control-group">
<input type="text" data-field="x_cuotas" name="x_cuotas" id="x_cuotas" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->cuotas->PlaceHolder) ?>" value="<?php echo $creditos->cuotas->EditValue ?>"<?php echo $creditos->cuotas->EditAttributes() ?>>
</span>
<?php echo $creditos->cuotas->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->diaVto->Visible) { // diaVto ?>
	<tr id="r_diaVto">
		<td><span id="elh_creditos_diaVto"><?php echo $creditos->diaVto->FldCaption() ?></span></td>
		<td<?php echo $creditos->diaVto->CellAttributes() ?>>
<span id="el_creditos_diaVto" class="control-group">
<input type="text" data-field="x_diaVto" name="x_diaVto" id="x_diaVto" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->diaVto->PlaceHolder) ?>" value="<?php echo $creditos->diaVto->EditValue ?>"<?php echo $creditos->diaVto->EditAttributes() ?>>
</span>
<?php echo $creditos->diaVto->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->observacion->Visible) { // observacion ?>
	<tr id="r_observacion">
		<td><span id="elh_creditos_observacion"><?php echo $creditos->observacion->FldCaption() ?></span></td>
		<td<?php echo $creditos->observacion->CellAttributes() ?>>
<span id="el_creditos_observacion" class="control-group">
<textarea data-field="x_observacion" name="x_observacion" id="x_observacion" cols="35" rows="4" placeholder="<?php echo ew_HtmlEncode($creditos->observacion->PlaceHolder) ?>"<?php echo $creditos->observacion->EditAttributes() ?>><?php echo $creditos->observacion->EditValue ?></textarea>
</span>
<?php echo $creditos->observacion->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->monto->Visible) { // monto ?>
	<tr id="r_monto">
		<td><span id="elh_creditos_monto"><?php echo $creditos->monto->FldCaption() ?></span></td>
		<td<?php echo $creditos->monto->CellAttributes() ?>>
<span id="el_creditos_monto" class="control-group">
<input type="text" data-field="x_monto" name="x_monto" id="x_monto" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->monto->PlaceHolder) ?>" value="<?php echo $creditos->monto->EditValue ?>"<?php echo $creditos->monto->EditAttributes() ?>>
</span>
<?php echo $creditos->monto->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->sucursal->Visible) { // sucursal ?>
	<tr id="r_sucursal">
		<td><span id="elh_creditos_sucursal"><?php echo $creditos->sucursal->FldCaption() ?></span></td>
		<td<?php echo $creditos->sucursal->CellAttributes() ?>>
<span id="el_creditos_sucursal" class="control-group">
<select data-field="x_sucursal" id="x_sucursal" name="x_sucursal"<?php echo $creditos->sucursal->EditAttributes() ?>>
<?php
if (is_array($creditos->sucursal->EditValue)) {
	$arwrk = $creditos->sucursal->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($creditos->sucursal->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `sucursales`";
$sWhereWrk = "";

// Call Lookup selecting
$creditos->Lookup_Selecting($creditos->sucursal, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_sucursal" id="s_x_sucursal" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`id` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $creditos->sucursal->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($creditos->nivelMorosidad->Visible) { // nivelMorosidad ?>
	<tr id="r_nivelMorosidad">
		<td><span id="elh_creditos_nivelMorosidad"><?php echo $creditos->nivelMorosidad->FldCaption() ?></span></td>
		<td<?php echo $creditos->nivelMorosidad->CellAttributes() ?>>
<span id="el_creditos_nivelMorosidad" class="control-group">
<input type="text" data-field="x_nivelMorosidad" name="x_nivelMorosidad" id="x_nivelMorosidad" size="30" placeholder="<?php echo ew_HtmlEncode($creditos->nivelMorosidad->PlaceHolder) ?>" value="<?php echo $creditos->nivelMorosidad->EditValue ?>"<?php echo $creditos->nivelMorosidad->EditAttributes() ?>>
</span>
<?php echo $creditos->nivelMorosidad->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</td></tr></table>
<?php
	if (in_array("cuotascredito", explode(",", $creditos->getCurrentDetailTable())) && $cuotascredito->DetailEdit) {
?>
<?php include_once "cuotascreditogrid.php" ?>
<?php } ?>
<button class="btn btn-primary ewButton" name="btnAction" id="btnAction" type="submit"><?php echo $Language->Phrase("EditBtn") ?></button>
</form>
<script type="text/javascript">
fcreditosedit.Init();
<?php if (EW_MOBILE_REFLOW && ew_IsMobile()) { ?>
ew_Reflow();
<?php } ?>
</script>
<?php
$creditos_edit->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");

</script>
<?php include_once "footer.php" ?>
<?php
$creditos_edit->Page_Terminate();
?>
